package com.popo.android.service;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Messenger;
import android.view.ViewDebug.FlagToString;

import com.popo.android.R;
import com.popo.android.activity.BaseActivity;

public class MessagerService extends Service {
    public static final int SAY_HELLO=1;
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    private Handler handler = new Handler(){
        public void handleMessage(android.os.Message msg) {
            switch(msg.what){
                case SAY_HELLO:
                    showNotification("hello");
                    break;
                    default:
                        break;
            }
        };
    };
    private final Messenger m = new Messenger(handler );
    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        System.out.println("MessagerSerice onBind");
        return m.getBinder();
    }
    
    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        System.out.println("MessagerSerice onCreate");
        super.onCreate();
    }
    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        System.out.println("MessagerSerice onDestroy");
        super.onDestroy();
    }
    protected void showNotification(String tickerText) {
        System.out.println("MessagerSerice showNotification");
        // TODO Auto-generated method stub
        Notification notification= new Notification(R.drawable.about_bg, tickerText, System.currentTimeMillis() );
        PendingIntent pendingIntent= PendingIntent.getActivity(this, 1, new Intent(this,BaseActivity.class), PendingIntent.FLAG_CANCEL_CURRENT);
        notification.setLatestEventInfo(this, "Hello", "hello2", pendingIntent);
        notificationManager.notify(1, notification);
    }

}
